define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task_statistics/index' + location.search,
                    add_url: 'task_statistics/add',
                    edit_url: 'task_statistics/edit',
                    del_url: 'task_statistics/del',
                    multi_url: 'task_statistics/multi',
                    import_url: 'task_statistics/import',
                    table: 'task_statistics',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'date', title: __('日期'), sortable: true,operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'app.name', title: __('应用名'), operate: false},
                        {field: 'app_id', title: __('应用名'),addclass: 'selectpage', extend:'data-source="app/index" ',visible:false,defaultValue:'1'},

                        {field: 'task_1', title: __('任务1完成数量'),sortable: true,operate: false},
                        {field: 'task_2', title: __('任务2完成数量'),sortable: true,operate: false},
                        {field: 'task_3', title: __('任务3完成数量'),sortable: true,operate: false},
                        {field: 'task_4', title: __('任务4完成数量'),sortable: true,operate: false},
                        {field: 'task_5', title: __('任务5完成数量'),sortable: true,operate: false},
                        {field: 'task_6', title: __('任务6完成数量'),sortable: true,operate: false}
                       /* {field: 'app.id', title: __('App.id')},
                        {field: 'app.app_id', title: __('App.app_id'), operate: 'LIKE'},

                        {field: 'app.packagename', title: __('App.packagename'), operate: 'LIKE'},
                        {field: 'app.status', title: __('App.status'), formatter: Table.api.formatter.status},
                        {field: 'app.addtime', title: __('App.addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},*/
                       /* {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});